<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %><%--
  Created by IntelliJ IDEA.
  User: YT
  Date: 2020/10/21
  Time: 20:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>个人中心</title>
    <%--引入css文件和js文件--%>
    <link rel="stylesheet" href="css/bootstrap.css">

    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.js"></script>
    <script src="js/bootstrap.bundle.js"></script>
    <style>
        .container{
            margin-top:20px;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <h3 style="text-align: center">用户所有信息</h3>
            <a href="#modal-container-addUser" role="button" class="btn" data-toggle="modal">添加用户</a>
            <a href="check.jsp"  class="btn">查看所有问卷</a>
            <table class="table table-striped">
                <thead>
                <th>ID</th>
                <th>用户名</th>
                <th>用户密码</th>
                <th>操作</th>
                </thead>
                <tbody>
                    <%
                        if (session.getAttribute("username") == null) {
        //表示尚未登陆
        out.print("你尚未登陆，3秒之后跳转登陆页面");
        response.setHeader("refresh", "3;nur=login.jsp");
    }else {
        //加载驱动
        Class.forName("com.mysql.jdbc.Driver");

        //建立数据库连接
        String url = "jdbc:mysql://localhost:3306/book";//数据库连接地址
        Connection connection = DriverManager.getConnection(url, "root", "root");

        //stmt.executeUpdate()执行增删改的驱动
        String sql = "select * from user ";
        PreparedStatement ps = connection.prepareStatement(sql);

        ResultSet rs = ps.executeQuery();//执行查询的函数 返回结果集
        while (rs.next()) {
            out.print("<td>"+rs.getInt("id")+"</td>"
                    +"<td>"+rs.getString("username") +"</td>"
                    +"<td>"+rs.getString("gender") +"</td>"
                    +"<td><a href='delete.jsp?id="+rs.getInt("id")+"'>删除</a>");
            out.print("</tr>");
        }
    }
%>
            </table>
            </table>
            <div class="modal fade" id="modal-container-addUser" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 class="modal-title" id="myModalLabel">添加问卷</h4>
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        </div>
                        <form role="form" method="post" action="add.jsp">
                            <div class="modal-body">
                                <div class="form-group">
                                    <label>用户名:</label><input type="text" name="username" class="form-control" />
                                </div>
                                <div class="form-group">
                                    <label>密码:</label><input type="password" name="password" class="form-control" />
                                </div>

                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                <button type="submit" class="btn btn-primary">添加</button>
                            </div>
                        </form>
                    </div>

                </div>

            </div>

        </div>
    </div>
</div>
</body>
</html>
